<?php

    // TODO: Timeout
    // TODO: Values = Arrays?
    // TODO: Check user authenticated?

    namespace framework;
    class session
    {
        public function __construct()
        {
            session_save_path(dirname(dirname(__DIR__)) . '/sessions/');
            session_name(project::getInstance() -> name);
            $webBasePath = dirname($_SERVER['SCRIPT_NAME']);
            if($webBasePath != '/')
            {
                $webBasePath .= '/';
            }
            session_set_cookie_params(0, $webBasePath, $_SERVER['SERVER_NAME'], false, true);
            session_start();
        }
        public function __set($variableName, $variableValue)
        {
            $_SESSION[$variableName] = $variableValue;
        }
        public function __get($variableName)
        {
            if(isset($_SESSION[$variableName]))
            {
                return $_SESSION[$variableName];
            }
            else
            {
                return false;
            }
        }
        public function finish()
        {
            $_SESSION = array();
            session_regenerate_id(true);
        }
    }